var api = require('../../../utils/api.js')
var $ = require('../../../utils/util.js')
var regeneratorRuntime = require('../../../utils/runtime.js')
var app = getApp()


Page({
  data: {
    company: '', // 公司
    factory:'', // 站房
    equipment: '', // 设备
    ticket_num: '', // 巡检订单号
    tabList: [{ name: '', type: 1, icon: 'icon-shijian' }, { name: '已查看', type: 2, icon: 'icon-tick' }], // tab
    currentTab: 0,
  },
  onLoad: function (options) {
    var tabList = this.data.tabList
    this.setData({
      company: options.company || '', 
      factory: options.factory || '', 
      equipment: options.equipment || '',  
      ticket_num: options.ticket_num || '',
      currentTab: options.currentTab || 0
    })

    if (this.data.ticket_num == '') { // 巡检订单号【本次需解决要传，全部未解决不传】
      tabList[0].name = '需解决'
    } else {
      tabList[0].name = '待解决'
    }

    this.setData({ tabList})

    this._initData() //初始化数据 

  },
  onShow: function () {

  },
 
  onPullDownRefresh: function () { // 下拉刷新 
  },

  _initData(){ // 初始化数据
    var params = { 
      type: this.data.tabList[this.data.currentTab].type,
      company: this.data.company,
      factory: this.data.factory,
      equipment: this.data.equipment,
      ticket_num: this.data.ticket_num
    }

    api.$post(api.pollingManage.defectRecord, params).then((res) => {
      this.setData({
        pageList: res.data
      })
    }) 
  },

  tabHanlde(e){ // 点击tab
    var {index} = e.detail
    this.setData({
      currentTab: index 
    })
    this._initData()
  }
   
})